package com.itita.ww2.utils.channel.payment;

import com.itita.ww2.utils.TimeUtil;
import com.itita.ww2.utils.UUIDGenerator;

public class OrderInfo {
	protected String orderId; // 订单id
	protected int channel; // 订单渠道
	protected long genericTime; // 生成订单时间
	protected long purchaseTime; // 支付时间
	protected String productId; // 商品id (完整 com.itita.cc0001)
	protected String sku; // 商品id (cc0001)

	public OrderInfo(String orderId) {
		this.orderId = orderId;
	}

	public static OrderInfo newOrder() {
		OrderInfo ret = new OrderInfo(UUIDGenerator.nextOrderId());
		ret.genericTime = TimeUtil.getUtcNowMillis();
		return ret;
	}

	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public long getPurchaseTime() {
		return purchaseTime;
	}

	public void setPurchaseTime(long purchaseTime) {
		this.purchaseTime = purchaseTime;
	}

	public long getGenericTime() {
		return genericTime;
	}

	public void setProductId(String productId) {
		this.productId = productId;
		this.sku = productId.substring(productId.lastIndexOf('.') + 1).toUpperCase();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof OrderInfo) {
			return ((OrderInfo) obj).orderId == this.orderId;
		}
		return false;
	}

	public String getSKU() {
		return sku;
	}
}
